package com.gitee.mazhenggg.demo.base.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.mazhenggg.demo.base.entity.SysUser;
import com.gitee.mazhenggg.demo.base.service.SysUserService;
import io.opentelemetry.extension.annotations.WithSpan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mazhenggg
 * @since 2021-08-25
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class SysUserController {
    @Autowired
    SysUserService sysUserService;
    @GetMapping("/un/info")
    public String testUn(HttpServletRequest request, HttpServletResponse response){
        Enumeration<String> names= request.getHeaderNames();
        String traceid = request.getHeader("x-b3-traceid");
        String spanid = request.getHeader("x-b3-spanid");
        String parentspanid = request.getHeader("x-b3-parentspanid");

        log.trace("trace");
        log.debug("debug");
        log.info("info");
        log.info(traceid);
        log.info(spanid);
        log.info(parentspanid);
        log.warn("warn");
        log.error("error");
        Integer i=sysUserService.count();
        System.out.println(i);
        //SysUser su=sysUserService.getById(1);
        testSpan();
        return "test";
    }
    @GetMapping("/info")
    public String test(){
        log.trace("trace");
        log.debug("debug");
        log.info("info");
        log.warn("warn");
        log.error("error");
        Integer i=sysUserService.count();
        System.out.println(i);
        //SysUser su=sysUserService.getById(1);
        testSpan();
        return "test";
    }
    @WithSpan(value = "testSpan")
    public void testSpan(){
        log.info("test span");
    }


    @GetMapping("/info/{username}")
    public SysUser info(@PathVariable String username) {
        SysUser user = sysUserService.getOne(Wrappers.<SysUser>query().lambda().eq(SysUser::getUsername, username));

        return user;
    }
}
